package test0701;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class PsDelete {

	public static void main(String[] args) {
		// 4:用 PreparedStatement 实现删除功能（表随意）
		Connection connection = null;
		PreparedStatement pstmt = null;

		try {
			Class.forName("com.mysql.jdbc.Driver");
			String url = "jdbc:mysql://localhost:3306/myschool?useSSL=false";
			connection = DriverManager.getConnection(url, "root", "zy940425");
			String sql = "delete from test0703 where name=?";
			pstmt = connection.prepareStatement(sql);
			pstmt.setString(1, "赵六");
			System.out.println(sql);
			System.out.println(pstmt.executeUpdate() + "条删除成功！");

		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				if (pstmt != null)
					pstmt.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			try {
				if (connection != null)
					connection.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

	}

}
